<template>
  <div>
    <div class="grid-content">
      <h2 style="text-align: center;">解调系统配置修改</h2>

      <el-form :model="dataForm" ref="dataForm" label-width="200px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="标定系数" prop="attenuation">
              <el-input
                v-model="dataForm.calibrationFactor"
                placeholder="标定系数"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="解调算法" prop="demodulationMethod">
              <el-select
                v-model="dataForm.demodulationMethod"
                clearable
                placeholder="解调算法"
              >
                <el-option :value="1" label="Buneman" />
                <el-option :value="2" label="质心法" />
                <el-option :value="3" label="高斯多项式拟合" />
                <el-option :value="4" label="高斯拟合" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="位移变化速率阈值" prop="changeRateThreshold">
              <el-input
                v-model="dataForm.changeRateThreshold"
                placeholder="位移变化速率阈值"
              >
                <i
                  slot="suffix"
                  style="font-style:normal;margin-right: 10px; line-height: 30px;"
                  >毫米</i
                >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="最大位移变化阈值" prop="changeMaxThreshold">
              <el-input
                v-model="dataForm.changeMaxThreshold"
                placeholder="最大位移变化阈值"
              >
                <i
                  slot="suffix"
                  style="font-style:normal;margin-right: 10px; line-height: 30px;"
                  >毫米</i
                >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="解调时间间隔" prop="demodulationInterval">
              <el-input
                v-model="dataForm.demodulationInterval"
                placeholder="请输入解调时间间隔"
              >
                <i
                  slot="suffix"
                  style="font-style:normal;margin-right: 10px; line-height: 30px;"
                  >分钟</i
                >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="添加整点扫描时间">
              <el-select
                v-model="dataForm.timePoints"
                multiple
                placeholder="请选择整点扫描时间"
              >
                <el-option
                  v-for="item in timeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="容差范围" prop="toleranceRange">
              <el-input
                v-model="dataForm.toleranceRange"
                placeholder="容差范围"
              >
                <i
                  slot="suffix"
                  style="font-style:normal;margin-right: 10px; line-height: 30px;"
                  >pm</i
                >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="插值算法" prop="interpolationMethod">
              <el-select
                v-model="dataForm.interpolationMethod"
                clearable
                placeholder="插值算法"
              >
                <el-option :value="0" label="线性插值" />
                <el-option :value="1" label="分段三次插值" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <el-button
          style="text-align: center;"
          type="primary"
          @click="reboot1()"
          icon="el-icon-success"
          >{{ reboot == 0 ? " 重启" : "正在重启中" }}</el-button
        >
        <el-button
          style="text-align: center;"
          type="primary"
          @click="dataFormSubmit()"
          icon="el-icon-success"
          >保存</el-button
        >
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataForm: {
        demodulationInterval: "",
        toleranceRange: "",
        demodulationMethod: "",
        changeRateThreshold: "",
        changeMaxThreshold: "",
        calibrationFactor: "",
        timePoints: "",
        interpolationMethod: "",
        currentWaterValue: ""
      },
      reboot: 0,
      timeOptions: [
        {
          value: "00:00:00",
          label: "00:00:00"
        },
        {
          value: "01:00:00",
          label: "01:00:00"
        },
        {
          value: "02:00:00",
          label: "02:00:00"
        },
        {
          value: "03:00:00",
          label: "03:00:00"
        },
        {
          value: "04:00:00",
          label: "04:00:00"
        },
        {
          value: "05:00:00",
          label: "05:00:00"
        },
        {
          value: "06:00:00",
          label: "06:00:00"
        },
        {
          value: "07:00:00",
          label: "07:00:00"
        },
        {
          value: "08:00:00",
          label: "08:00:00"
        },
        {
          value: "09:00:00",
          label: "09:00:00"
        },
        {
          value: "10:00:00",
          label: "10:00:00"
        },
        {
          value: "11:00:00",
          label: "11:00:00"
        },
        {
          value: "12:00:00",
          label: "12:00:00"
        },
        {
          value: "13:00:00",
          label: "13:00:00"
        },
        {
          value: "14:00:00",
          label: "14:00:00"
        },
        {
          value: "15:00:00",
          label: "15:00:00"
        },
        {
          value: "16:00:00",
          label: "16:00:00"
        },
        {
          value: "17:00:00",
          label: "17:00:00"
        },
        {
          value: "18:00:00",
          label: "18:00:00"
        },
        {
          value: "19:00:00",
          label: "19:00:00"
        },
        {
          value: "20:00:00",
          label: "20:00:00"
        },
        {
          value: "21:00:00",
          label: "21:00:00"
        },
        {
          value: "22:00:00",
          label: "22:00:00"
        },
        {
          value: "23:00:00",
          label: "23:00:00"
        }
      ]
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.$http({
        url: this.$http.adornUrl("/generator/config/lasted/config"),
        method: "get"
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataForm.demodulationInterval = data.config.demodulationInterval;
          this.dataForm.toleranceRange = data.config.toleranceRange;
          this.dataForm.demodulationMethod = data.config.demodulationMethod;
          this.dataForm.changeRateThreshold = data.config.changeRateThreshold;
          this.dataForm.changeMaxThreshold = data.config.changeMaxThreshold;
          this.dataForm.calibrationFactor = data.config.calibrationFactor;
          this.dataForm.interpolationMethod = data.config.interpolationMethod;
          this.dataForm.currentWaterValue = data.config.currentWaterValue;
          this.reboot = data.config.reboot;
          if (data.config.timePoints != "") {
            this.dataForm.timePoints = data.config.timePoints.split(",");
          } else {
            this.dataForm.timePoints = data.config.timePoints;
          }
        }
      });
    },
    // select多选框设置回显

    // 表单提交
    dataFormSubmit() {
      // 将时间数组转为字符串
      this.dataForm.timePoints = this.dataForm.timePoints.toString();
      this.$http({
        url: this.$http.adornUrl("/generator/config/save"),
        method: "post",
        data: this.$http.adornData(this.dataForm, false)
      }).then(({ data }) => {
        // 提示信息
        this.$message({
          message: "修改成功",
          type: "success"
        });
        // 刷新页面
        this.init();
      });
    },
    reboot1() {
      this.$confirm("此操作将对硬件设备进行重启?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl("/generator/config/reboot"),
          method: "get",
          params: this.$http.adornParams({})
        }).then(({ data }) => {
          if (data.code == 0) {
            this.$message({
              type: "success",
              message: "正在重启中!"
            });
            this.reboot = 1;
          }
          // 刷新页面
          this.init();
        });
      });
    }
  }
};
</script>

<style>
.el-select__tags {
  white-space: nowrap;
  overflow: hidden;
}
</style>
